import request from '@/utils/request'
import Cookies from 'js-cookie'
import {setTemplateBody} from "@/utils/auth";
export function getTemplateList(limit = 100, page = 1, params) {
  return request({
    url: `table/assembly/list/${limit}/${page}`,
    method: 'get',
    params
  })
}

export function getInspection(params) {
  return request({
    url: `table/data/inspection`,
    method: 'get',
    params
  })
}

export function getTemplateBody(limit = 100, page = 1) {
  console.log('1');
  return request({
    url: `table/template/body/list/${limit}/${page}`,
    method: 'get'
  }).then(response => {
    const data = response.data;
    setTemplateBody(data.data); // 将响应数据保存到 cookie 中
    console.log('asdasdasdddddddddddddddddd');
    return response; // 继续将响应返回给调用者
  });
}

export function getTemplateHeader(limit = 100, page = 1) {
  return request({
    url: `table/template/header/list/${limit}/${page}`,
    method: 'get'
  })
}
export function getTemplateTail(limit = 100, page = 1) {
  return request({
    url: `table/template/tail/list/${limit}/${page}`,
    method: 'get'
  })
}

export function addTemplate(data) {
  return request({
    url: `table/assembly/add`,
    method: 'POST',
    data
  })
}

export function modifyTemplate(aid, data) {
  return request({
    url: `table/assembly/alter/${aid}`,
    method: 'POST',
    data
  })
}

export function addDraft(data) {
  return request({
    url: `table/draft/add`,
    method: 'POST',
    data
  })
}

export function uploadOrderFile(data, tid) {
  return request({
    url: `upload/single/${tid}`,
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data
  })
}

export function publishDraftAsFree(tid) {
  return request({
    url: `table/draft/store//${tid}`,
    method: 'POST'
  })
}

export function publishDraft(tid) {
  return request({
    url: `table/draft/publish/${tid}`,
    method: 'POST'
  })
}

export function deleteDraft(tid) {
  return request({
    url: `table/draft/${tid}`,
    method: 'DELETE'
  })
}

export function getDraftList(limit, page, params) {
  return request({
    url: `table/draft/list/${limit}/${page}`,
    method: 'get',
    params
  })
}

export function modifyDraft(tid, data) {
  return request({
    url: `table/draft/alter/${tid}`,
    method: 'POST',
    data
  })
}

export function getFile(tid) {
  return request({
    url: `upload/table/${tid}`,
    method: 'GET'
  })
}

export function deleteFile(fid) {
  return request({
    url: `upload/my/${fid}`,
    method: 'DELETE'
  })
}

export function archiveOrder(tid) {
  return request({
    url: `table/archive/${tid}`,
    method: 'POST'
  })
}

export function moveOrder(tid, uid) {
  return request({
    url: `table/pass/${tid}/${uid}`,
    method: 'POST'
  })
}

export function getOrderByTid(tid) {
  return request({
    url: `table/find/${tid}`,
    method: 'GET'
  })
}

export function getToDoOrder(limit, page, params) {
  return request({
    url: `table/find/my/handling/${limit}/${page}`,
    method: 'get',
    params
  })
}

export function getMyRelatedOrder(limit, page, params) {
  return request({
    url: `table/find/my/${limit}/${page}`,
    method: 'get',
    params
  })
}

export function getAllOrder(limit, page, params) {
  return request({
    url: `table/list/${limit}/${page}`,
    method: 'get',
    params
  })
}

export function claimFreeOrder(tid) {
  return request({
    url: `table/store/claim/${tid}`,
    method: 'post'
  })
}

export function oCheck(tid, oid, data) {
  return request({
    url: `table/ocheck/${tid}/${oid}`,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data
  })
}

export function zCheck(tid, oid, data) {
  return request({
    url: `table/zcheck/${tid}/${oid}`,
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
export function sCheck(tid, oid, data) {
  return request({
    url: `table/scheck/${tid}/${oid}`,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data
  })
}

export function postProblem(tid, oid, data) {
  return request({
    url: `table/problem/${tid}/${oid}`,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data
  })
}

export function deleteProblem(tid, oid) {
  return request({
    url: `table/question/${tid}/${oid}`,
    method: 'DELETE'
  })
}

export function deleteProblemSign(tid, oid) {
  return request({
    url: `table/problem/sign/${tid}/${oid}`,
    method: 'DELETE'
  })
}

export function deleteRecordSign(tid, oid) {
  return request({
    url: `table/question/sign/${tid}/${oid}`,
    method: 'DELETE'
  })
}

export function postRecord(tid, oid, data) {
  return request({
    url: `table/problem/process/${tid}/${oid}`,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data
  })
}

export function deleteRecord(tid, oid) {
  return request({
    url: `table/question/sign/${tid}/${oid}`,
    method: 'delete'
  })
}

export function getRecord(tid) {
  return request({
    url: `table/${tid}/problemsign`,
    method: 'get'
  })
}

export function fillTableItem(tid, oid, data) {
  return request({
    url: `table/fill/${tid}/${oid}`,
    method: 'post',
    data
  })
}

export function download(tid) {
  return request({
    url: `table/file/${tid}`,
    method: 'post'
  })
}

export function toFreeStore(tid) {
  return request({
    url: `table/store/${tid}`,
    method: 'post'
  })
}

export function draftToFreeStore(tid) {
  return request({
    url: `table/draft/store/${tid}`,
    method: 'post'
  })
}

export function getProblems() {
  return request({
    url: `table/data/problems`,
    method: 'get'
  })
}

export function deleteTemplate(tid) {
  return request({
    url: `table/assembly/${tid}`,
    method: 'DELETE'
  })
}

export function saveReturn(tid, data) {
  return request({
    url: `table/return/${tid}`,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data
  })
}

export function getBodyByOid(oid) {
  return request({
    url: `table/template/body/detail/${oid}`,
    method: 'get'
  })
}

export function multiAdd(data){
  return request(
    {
      url:'table/multi/add',
      method:'post',
      data
    }
  )
}
